<template>
  <el-dialog
      :model-value="dialogVisible"
      :title="props.dialogJgTitle"
      width="40%"
      @close="handleClose"
  >
    <el-form :model="form" ref="formRef" label-width="90px" :rules="rules">
      <el-form-item label="产品名称" prop="cpmc">
        <el-select v-model="form.cpmc" clearable placeholder="请选择">
          <el-option
              v-for="(item, index) in CpName"
              :key="index"
              :label="item"
              :value="item"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="产品批次" prop="pch">
        <el-select v-model="form.pch" clearable placeholder="请选择">
          <el-option
              v-for="(item, index) in pchOptions"
              :key="index"
              :label="item"
              :value="item"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="加工过程" prop="processName">
        <el-input v-model="form.processName" />
      </el-form-item>
      <el-form-item label="图片名称">
        <el-input disabled v-model="tpmc" />
      </el-form-item>
      <el-form-item label="加工过程">
        <my-upload
            :file-type="'jggc'"
            @get-form-pic-value="getFormPicValue"
        >
        </my-upload>
      </el-form-item>
      <el-form-item label="加工方式">
        <el-input v-model="form.processWay" />
      </el-form-item>
      <el-form-item label="作业日期" prop="processTime">
        <el-date-picker
            v-model="form.processTime"
            type="date"
            placeholder="选择日期"
            :size="'default'"
            clearable
        />
      </el-form-item>
      <el-form-item label="负责人" prop="fzr">
        <el-input v-model="form.fzr" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleConfirm">
          确认
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import {defineEmits, ref, defineProps, watch, onMounted} from 'vue'
import {ElNotification} from "element-plus";
import {getAllCpmc, getAllPcCpmc, getPchByCpmc} from "@/api/apiPath/twoPart.js";
import {getOptionInfo, getOptionsInfo} from "@/api/methods/initInfo.js";
import MyUpload from "@/components/commons/myUpload.vue";

const props = defineProps({
  dialogJgTitle: {
    type: String,
    default: '',
    required: true
  },
  dialogJgTableValue: {
    type: Object,
    default: {}
  },
  queryForm: {
  },
  dialogVisible: {
    type: Boolean,
    default: false
  }
})
const tpmc = ref('')
const formRef = ref(null)
const form = ref({
  cpmc: '',
  pch: '',
  processName: '',
  processWay: '',
  processTime: '',
  createTime: '',
  fzr: '',
  processPic: ''
})
const CpName = ref([])
const pchOptions = ref([])
onMounted(async ()=> {
    CpName.value = await getOptionInfo(getAllPcCpmc())
  form.value = props.dialogJgTableValue
})
watch(()=> form.value.cpmc, async (cpmc)=> {
  console.log(cpmc)
  if (form.value.cpmc != null && form.value.cpmc !== "") {
    // console.log(props.dialogJgTableValue.cpmc)
    pchOptions.value = await getOptionInfo(getPchByCpmc(cpmc))
    console.log(pchOptions.value)
    form.value.pch = ''
  }
}, {deep: true, immediate: true})
const rules = ref({
  pch: [{
    required: true,
    message: '不能为空',
    trigger: ['blur', 'change'],
  }],
  cpmc: [{
    required: true,
    message: '不能为空',
    trigger: ['blur', 'change'],
  }],
  fzr: [{
    required: true,
    message: '不能为空',
    trigger: ['blur', 'change'],
  }],
})
const emits = defineEmits(['update:modelValue', 'handleConfirm'])
const handleClose = ()=> {
  emits('update:modelValue', false)
}
const handleConfirm = () => {
  emits("handleConfirm", {...form.value}, {...formRef.value})
}
const getFormPicValue = (value)=> {
  console.log(value)
  form.value.processPic = value.pic
  tpmc.value = value.tpmc
}

</script>

<style scoped>


</style>



